package org.je.refl;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

/**
 * @author fanyifeng
 */
public class FieldUtil
{
	/**
	 * @param f
	 * @return bool
	 */
	public static boolean isFinal(Field f) {
		return Modifier.isFinal(f.getModifiers());
	}

	/**
	 * @param f
	 * @param obj
	 * @param val
	 */
	public static void set(Field f, Object obj, Object val) {
		try {
			f.set(obj, val);
		} catch (Exception ex) {
			throw new RuntimeException(ex);
		}
	}

	/**
	 * @param f
	 * @param obj
	 * @return val
	 */
	public static Object get(Field f, Object obj) {
		try {
			return f.get(obj);
		} catch (Exception ex) {
			throw new RuntimeException(ex);
		}
	}
}
